package com.eightbears.beboy.ui.merchant.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.eightbears.beboy.R;
import com.eightbears.beboy.base.BaseActivity;
import com.eightbears.beboy.base.util.GsonUtil;
import com.eightbears.beboy.base.util.SPUtil;
import com.eightbears.beboy.base.util.okhttp.OkHttpUtils;
import com.eightbears.beboy.base.util.okhttp.callback.StringCallback;
import com.eightbears.beboy.base.view.SwipeBackLayout;
import com.eightbears.beboy.entity.TagsEntity;
import com.socks.library.KLog;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

import static com.eightbears.beboy.base.util.CommonAPI.KEY_HTTP_HEADER;
import static com.eightbears.beboy.base.util.CommonAPI.URL_ADDSHOPTECHNICIAN_TAGS;

public class TechnicianTagsActivity extends BaseActivity {
    @BindView(R.id.sw)
    SwipeBackLayout sw;
    @BindView(R.id.tv_title)
    TextView tv_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_technician_tags);
        initView();
        initData();
        initEvent();
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        tv_title.setText("标签选择");
    }

    @Override
    protected void initData() {

        getData();
    }

    private void getData() {
        //获取accesstoken
        OkHttpUtils.get().url(URL_ADDSHOPTECHNICIAN_TAGS)
                .addHeader(KEY_HTTP_HEADER, "Bearer " + SPUtil.getAccessToken())
                .build().execute(new StringCallback() {

            @Override
            public void onError(Call request, Exception e) {
                KLog.e(e.getMessage());
            }

            //TODO
            @Override
            public void onResponse(String response) {
                KLog.e(response);
                try {
                    TagsEntity tagsEntity = GsonUtil.fromJson(response, TagsEntity.class);
                    List<TagsEntity.DataBean> data = tagsEntity.getData();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

    }

    @OnClick(R.id.ll_back)
    void back() {
        finish();
    }

    @Override
    protected void initEvent() {
        sw.setCallBack(new SwipeBackLayout.CallBack() {
            @Override
            public void onFinish() {
                finish();
            }
        });
    }
}
